package com.vtuzx.kingdee.xqc_api.web;

import com.vtuzx.core.VtuzxException;
import com.vtuzx.core.bean.dto.VtuzxToken;
import com.vtuzx.core.constant.IVtuzxConst;
import com.vtuzx.core.utils.VtuzxUtil;
import com.vtuzx.kingdee.xqc_api.service.IXqcTraceBackService;
import com.vtuzx.kingdee.xqc_api.service.IXqcTrayService;
import com.vtuzx.web.constant.ApiType;
import com.vtuzx.web.web.VtuzxApi;
import com.vtuzx.web.web.VtuzxControlParam;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 调拨
 */
@RequestMapping("/${vtuzx.fast.api.path}/${vtuzx.fast.api.version}/trace_back")
@RestController
public class XqcTraceBackController {

    @Autowired
    IXqcTraceBackService traceBackService;


    /**
     * 追溯码绑定箱子
     */
    @PostMapping("/trace_back_code_bink_boxNo")
    @VtuzxApi
    public Object traceBackCodeBinkBoxNo(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return traceBackService.traceBackCodeBinkBoxNo(_userId, name, param);

    }

    /**
     * 查询追溯码信息
     */
    @PostMapping("/get_trace_back_code_data")
    @VtuzxApi
    public Object getTraceBackCodeData(@RequestBody Map<String, Object> param) throws VtuzxException {
        return traceBackService.getTraceBackCodeData(param);

    }

    /**
     * 更新追溯信息维护
     */
    @PostMapping("/update_trace_back_data")
    @VtuzxApi
    public Object updateTraceBackData(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        traceBackService.updateTraceBackData(param);
        return null;
    }


    /**
     * 获取追溯信息
     */
    @PostMapping("/get_trace_back_data")
    @VtuzxApi
    public Object getTraceBackData(@RequestBody Map<String, Object> param) throws VtuzxException {
        return traceBackService.getTraceBackData(param);

    }

    /**
     * 选择行下载追溯信息
     */
    @PostMapping("/download_trace_back_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadTraceBackList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        return traceBackService.downloadTraceBackList(_userId, param);
    }

    /**
     * 根据追溯码查询生产信息，检测中心等信息
     */
    @PostMapping("/get_traceBack_to_data")
    @VtuzxApi
    public Object getTraceBackToData(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        return traceBackService.getTraceBackToData(_userId, param);
    }




}
